﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DARE.Save.DataStructures
{
    public class CCameraData: ISaveData
    {
        public bool ManualAspectRatio;
        public bool IsActive;
        public bool Updatable;
        public bool KeepTransform;
        public bool AttachedToNode;
        public Matrix Projection;
        public Matrix View;
        public float NearPlane;
        public float FarPlane;
        public float AspectRatio;
        public float FovY;
        public Vector3 Position;
        public Quaternion Orientation;
        public Vector3 Heading;
        public Vector3 Up;
        public Vector3 Strafe;
        public Vector3 Target;
        public string Name;
        public string Node;


        public virtual void FillDataStructure(object cam)
        {
            CCamera camera = cam as CCamera;
            Name = camera.Name;
            IsActive = camera.IsActive;
            Heading = camera.Heading;
            AspectRatio = camera.AspectRatio;
            AttachedToNode = camera.AttachedToNode;
            FarPlane = camera.FarPlane;
            FovY = camera.FovY;
            KeepTransform = camera.KeepTransform;
            ManualAspectRatio = camera.ManualAspectRatio;
            NearPlane = camera.NearPlane;
            if (camera.Node != null)
                Node = camera.Node.Name;
            Orientation = camera.Orientation;
            Position = camera.Position;
            Projection = camera.Projection;
            Strafe = camera.Strafe;
            Target = camera.Target;
            Up = camera.Up;
            Updatable = camera.Updatable;
            View = camera.View;
        }

        public virtual void FillFromDataStructure(out object camera, params object[] paramsData)
        {
            CCamera cam = CreateInstance();

            cam.IsActive = IsActive;
            cam.AspectRatio = AspectRatio;
            cam.FarPlane = FarPlane;
            cam.FovY = FovY;
            cam.KeepTransform = KeepTransform;
            cam.ManualAspectRatio = ManualAspectRatio;
            cam.NearPlane = NearPlane;
            cam.Orientation = Orientation;
            cam.Position = Position;
            cam.Projection = Projection;
            cam.Target = Target;
            cam.Updatable = Updatable;

            if (paramsData.Length > 0 && paramsData[0] is DARE.CRender3D)
            {
                if (AttachedToNode && Node != null && Node != string.Empty)
                    cam.AttachToNode((paramsData[0] as DARE.CRender3D).GetNode(Node));
            }
            camera = cam;
        }

        public virtual CCamera CreateInstance()
        {
            return new CCamera(Name);
        }
    }
}
